<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/7/4
 * Time: 下午2:16
 */

namespace app\admin\controller;


use app\src\deleteApply\logic\DeleteApplyLogic;

class DeleteApply extends Admin
{
    /**
     * 删除申请列表
     */
    public function applyList()
    {

        if(IS_AJAX){

            if(!$this->isBackAdmin()){
                $this->error('没有权限查看此内容');
            }

            $p = $this->_param('p', 1);
            $size = $this->_param('size', 15);
            $page = ['curpage' => $p, 'size' => $size];
            $apply_status = $this->_param('apply_status', 0);
            if(!in_array($apply_status,[0, 1, 2])) $this->error('error apply_status');

            $result = (new DeleteApplyLogic)->applyList($page, $apply_status);

            if($result['status']){
                $this->success('获取删除申请列表成功', null, $result['info']);
            }else{
                $this->error('获取删除申请列表失败', null, $result['info']);
            }
        }

    }

    /**
     * 删除申请结果列表
     */
    public function queryList()
    {

        if(IS_AJAX){

            if(!$this->isBackAdmin()){
                $this->error('没有权限查看此内容');
            }

            $p = $this->_param('p', 1);
            $size = $this->_param('size', 15);
            $page = ['curpage' => $p, 'size' => $size];
            $apply_status = ['in', [1, 2]];

            $result = (new DeleteApplyLogic)->applyList($page, $apply_status);

            if($result['status']){
                $this->success('获取提现申请结果列表成功', null, $result['info']);
            }else{
                $this->error('获取提现申请结果列表成功', null, $result['info']);
            }
        }

    }

    /**
     * 通过删除申请
     */
    public function passApply()
    {
        if(IS_AJAX){

            if(!$this->isBackAdmin()){
                $this->error('没有权限查看此内容');
            }

            $apply_id = $this->_param('apply_id');
            if(empty($apply_id)) $this->error('删除申请id缺失');

            $result = (new DeleteApplyLogic)->passApply($apply_id);

            if($result['status']){
                $this->success('操作成功', null, $result['info']);
            }else{
                $this->error('操作失败', null, $result['info']);
            }
        }
    }

    /**
     * 否决删除申请
     */
    public function rejectApply()
    {
        if(IS_AJAX){

            if(!$this->isBackAdmin()){
                $this->error('没有权限查看此内容');
            }

            $apply_id = $this->_param('apply_id');
            if(empty($apply_id)) $this->error('删除申请id缺失');

            $result = (new DeleteApplyLogic)->rejectApply($apply_id);

            if($result['status']){
                $this->success('操作成功', null, $result['info']);
            }else{
                $this->error('操作失败', null, $result['info']);
            }
        }
    }
}